﻿using System;
using System.Collections.Generic;
using System.Text;
using Cn.Edwon.Biz;
using Cn.Cellula.Model;
using System.Xml;
using System.Web.UI.WebControls;
using Cn.Edwon.Web.Session;
using Cn.Cellula.Model.Security;
using Cn.Edwon.Web.Ac;

namespace Cn.Cellula.Biz.Port {
    public interface IUserBiz : IBiz {

        #region 功能管理
        /// <summary>
        /// 根据父ID获取分类列表
        /// </summary>
        /// <param name="parentKey"></param>
        /// <returns></returns>
        IList<TSysFunctionEO> LoadFunctions(String parentKey);
        /// <summary>
        /// 将分类列表转换为json格式
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        String LoadFunctions2Json(ISessActor rActor,String parentKey);
        /// <summary>
        /// 将分类列表从某个节点开始转换为json格式
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        String LoadFunctions2Json(XmlNode rNode);
        /// <summary>
        /// 将分类数据从某个节点开始，转换为jskitmenu能够使用的数据格式
        /// </summary>
        /// <param name="rNode"></param>
        /// <returns></returns>
        String LoadFunctions2JskitMenuXml(ISessActor rActor, String parentKey);
        /// <summary>
        /// 将分类转化为优结构的xml格式
        /// </summary>
        /// <param name="firstId"></param>
        /// <returns></returns>
        XmlDocument LoadFunction2XHtml(ISessActor rActor,String parentKey);
        /// <summary>
        /// 删除功能
        /// </summary>
        /// <param name="rKeys"></param>
        void DeleteFunctions(String[] rKeys);
        /// <summary>
        /// 将分类转化为下拉列表的集合
        /// </summary>
        /// <param name="rParentKey"></param>
        /// <param name="rPrefix"></param>
        /// <returns></returns>
        IList<ListItem> LoadFunc2ListItem(ISessActor rActor, String rPrefix, String rSelfKey, Boolean rSelected);
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="rKeys"></param>
        void DeleteRoles(IList<String> rKeys);
        /// <summary>
        /// 根据角色删除角色功能关系
        /// </summary>
        /// <param name="rFuncKey"></param>
        void DeleteRoleFunctionByRole(String rRoleKey);
        /// <summary>
        /// 根据功能删除角色功能关系
        /// </summary>
        /// <param name="rFuncKey"></param>
        void DeleteRoleFunctionByFunc(String rFuncKey);

        /// <summary>
        /// 获取某个角色的功能选单
        /// </summary>
        /// <param name="rRoleKey"></param>
        /// <returns></returns>
        IList<TSysRoleFunctionEO> LoadRfByRole(String rRoleKey);

        /// <summary>
        /// 将功能绑定到角色
        /// </summary>
        /// <param name="Funcs"></param>
        /// <param name="rRoleKey"></param>
        void BindFunc2Role(String[] rFuncs, String rRoleKey);
        /// <summary>
        /// 查看角色是否有用户使用
        /// </summary>
        /// <param name="rRoleKey"></param>
        /// <returns></returns>
        Boolean IfRoleInUse(String rRoleKey);
        /// <summary>
        /// 根据角色获得Function的列表(无结构)
        /// </summary>
        /// <param name="rRoleKey"></param>
        /// <returns></returns>
        IList<VUserFunctionEO> LoadFuncByUser(String rUserKey);
        #endregion

        #region 用户管理
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="rKeys"></param>
        void DeleteUsers(IList<String> rKeys);
        /// <summary>
        /// 检查LoginName是否已经存在
        /// </summary>
        /// <param name="rLoginName"></param>
        Boolean IfLoginNameExists(String rLoginName,String rUserKey);
        /// <summary>
        /// 检查Email是否已经存在
        /// </summary>
        /// <param name="rEmail"></param>
        Boolean IfEmailExists(String rEmail, String rUserKey);
        /// <summary>
        /// 检查UserNo是否已经存在
        /// </summary>
        /// <param name="rUserNo"></param>
        /// <returns></returns>
        Boolean IfUserNoExist(String rUserNo, String rUserKey);
        /// <summary>
        /// UserName是否已经存在
        /// </summary>
        /// <param name="rUserName"></param>
        /// <returns></returns>
        Boolean IfUserNameExists(String rUserName, String rUserKey);
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="rUser"></param>
        /// <param name="rOldPwd"></param>
        /// <param name="rNewPwd"></param>
        /// <returns>0：成功，1：旧密码错误，2：异常</returns>
        int ChangePassword(String rUserKey,String rOldPwd,String rNewPwd);
        int ResetPassword(String rUserKey, String rNewPwd);
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="rLoginNameProperty"></param>
        /// <param name="rLoginName"></param>
        /// <param name="rPassword"></param>
        /// <param name="rActor"></param>
        VSysUserEO Login(String rLoginNameProperty, String rLoginName, String rMd5Pwd);
        /// <summary>
        /// 使用用户Key和密码登录
        /// </summary>
        /// <param name="rUserKey"></param>
        /// <param name="rPassword"></param>
        /// <param name="rActor"></param>
        VSysUserEO Login(String rUserKey, String rMd5Pwd);
        /// <summary>
        /// 生成用户编号
        /// </summary>
        /// <returns></returns>
        String GenerateUserNo();
        /// <summary>
        /// 根据UserPower列出比较低的用户，包括自己，不包括同级
        /// </summary>
        /// <param name="rUserId"></param>
        /// <returns></returns>
        IList<VSysUserEO> LoadLowerUser(String rUserKey,UserPower rPower,Boolean rHasSelf);

        #endregion

        #region 角色管理
        /// <summary>
        /// 根据操作者的角色等级，选择角色
        /// </summary>
        /// <param name="rActorRoleLevel"></param>
        /// <returns></returns>
        IList<TSysRoleEO> LoadAllRoles(Int32? rActorRoleLevel);
        /// <summary>
        /// 获取所有用户
        /// </summary>
        /// <returns></returns>
        IList<VSysUserEO> LoadAllUsers();
        #endregion

        #region Power管理
        /// <summary>
        /// 为对象绑定权限
        /// </summary>
        /// <param name="rObjectKey">对象KEY</param>
        /// <param name="rVisiableRoleKey">可见的角色的KEY</param>
        /// <param name="rEditableRoleKey">可编辑的角色的KEY</param>
        /// <param name="rOperator">操作者KEY</param>
        void BindPower(String rObjectKey, String rVisiableRoleKey, String rEditableRoleKey,String rDeptKey, String rOperator);
        #endregion
    }
}
